const { series, src, dest, watch, task } = require('gulp');
const sass = require('gulp-sass')(require('sass'));
const autoprefixer = require('gulp-autoprefixer');
const concat = require('gulp-concat');
const cssnano = require('gulp-cssnano');

function buildStyle() {
    return src('./src/*.scss')
        .pipe(sass())
        .pipe(concat('index.css'))
        .pipe(autoprefixer({
            overrideBrowserslist: ['last 2 versions'],
            cascade: false
        }))
        .pipe(cssnano())
        .pipe(dest('./lib/'))
}

function watchStyle() {
    return src('./src/*.scss')
        .pipe(sass())
        .pipe(concat('index.css'))
        .pipe(autoprefixer({
            overrideBrowserslist: ['last 2 versions'],
            cascade: false
        }))
        .pipe(dest('./lib/'))
}

exports.watch = series(() => {
    watch('./src', series(watchStyle))
})

exports.build = series(buildStyle);